package com.hrc.rpc.Filter;


import com.hrc.rpc.protocol.RpcRequest;
import com.hrc.rpc.protocol.RpcResponse;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Arrays;
import java.util.Map;

/**
 * 上下文数据
 */
@Data
@NoArgsConstructor
public class FilterData {


    private String serviceVersion;
    private long timeout;
    private long retryCount;
    private String className;
    private String methodName;
    private Object[] args;
    private Map<String, Object> serviceAttachments;
    private Map<String, Object> clientAttachments;
    private RpcResponse data; // 执行业务逻辑后的数据

    public FilterData(RpcRequest request) {
        this.args = request.getParams();
        this.className = request.getClassName();
        this.methodName = request.getMethodName();
        this.serviceVersion = request.getServiceVersion();
        this.serviceAttachments = request.getServiceAttachments();
        this.clientAttachments = request.getClientAttachments();
    }

    @Override
    public String toString() {
        return "调用: Class: " + className + " Method: " + methodName + " args: " + Arrays.toString(args) + " Version: " + serviceVersion
                + " Timeout: " + timeout + " ServiceAttachments: " + serviceAttachments +
                " ClientAttachments: " + clientAttachments;
    }

}
